﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace FurnitureSystem
{
    
    public partial class frmThemKH : Form
    {
        SqlConnection conn;
        SqlCommand cmd;
        SqlDataReader dr;
        public frmThemKH()
        {
            InitializeComponent();
        }
        
        private void BtnThoat_Click(object sender, EventArgs e)
        {
            this.Hide();
        }

        private void BtnThem_Click(object sender, EventArgs e)
        {
            if (txtDiachi.Text == "" || txtMaKH.Text == "" || txtSDT.Text == "" || txtTenKH.Text == ""|| txtOrderid.Text == "")
            {
                MessageBox.Show("Vui lòng điền đẩy đủ thông tin khách hàng trước khi hoàn tất");
            }
            else
            {
                conn = connect.Getconect();
                conn.Open();
                string sql = "insert into Customer values ('" + Int32.Parse(txtMaKH.Text) + "','" + txtTenKH.Text + "','" + txtSDT.Text + "','" + txtDiachi.Text + "','" + Int32.Parse(txtOrderid.Text) + "')";
                cmd = new SqlCommand(sql, conn);
                dr = cmd.ExecuteReader();
                MessageBox.Show("Đã thêm khách hàng vào CSDL");
                conn.Close();
                txtDiachi.Text = "";
                txtMaKH.Text = "";
                txtSDT.Text = "";
                txtTenKH.Text = "";
                txtOrderid.Text = "";
                txtMaKH.Focus();
            }
        }
    }
}
